package sdk;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ChargeSDK {
    private Client client;

    public ChargeSDK(Client client) {
        this.client = client;
    }

    public Map<String, Object> chargeStart(Object req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> combinedParams = new HashMap<>();
        if (req != null) {
            Class<?> clazz = req.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                try {
                    String fieldName = field.getName();
                    Object fieldValue = field.get(req);
                    combinedParams.put(fieldName, fieldValue);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to access field in chargeStart ", e);
                }
            }
        }
        Map<String, Object> postParams =buildClient.buildPostParam(combinedParams);
        return client.post("/open/charge/start", postParams);
    }

    public Map<String, Object> chargeStop(Object req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> combinedParams = new HashMap<>();
                if (req != null) {
            Class<?> clazz = req.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                try {
                    String fieldName = field.getName();
                    Object fieldValue = field.get(req);
                    combinedParams.put(fieldName, fieldValue);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to access field in chargeStop ", e);
                }
            }
        }
        Map<String, Object> postParams = buildClient.buildPostParam(combinedParams);
        return client.post("/open/charge/stop", postParams);
    }
}